package config

import (
	"gopkg.in/ini.v1"
)
type Config struct {
	//系统
	System struct {
		Address string
		Port    int
	}
	//数据库
	Mysql struct {
		Host     string
		Port     int
		Dbname   string
		Username string
		Password string
		Charset  string
	}
}

func (c *Config) InIt() *Config {

	path := "./config/config.ini"
	source, _ := ini.Load(path)
	c.System.Address = source.Section("system").Key("address").MustString("127.0.0.1")
	c.System.Port = source.Section("system").Key("address").MustInt(8080)
	c.Mysql.Host = source.Section("mysql").Key("host").MustString("127.0.0.1")
	c.Mysql.Port = source.Section("mysql").Key("port").MustInt(3306)
	c.Mysql.Dbname = source.Section("mysql").Key("dbname").MustString("")
	c.Mysql.Username = source.Section("mysql").Key("username").MustString("root")
	c.Mysql.Password = source.Section("mysql").Key("password").MustString("root")
	c.Mysql.Charset = source.Section("mysql").Key("charset").MustString("utf8")

	return c
}
